package controller;

import commands.controller.ControllerCommand;
import commands.controller.ControllerCommand.ControllerCommandType;

/**
 * Class implementing timer for informing Controller to clean and get new host for every file.
 * Only job done by this class is to write message to controller every 60 secs after creating instance.
 * @author Jakub Skierbiszewski
 *
 */
public class HostFinder implements Runnable
{
	private Controller ctrl;
	
	/**
	 * Constructor. Creates and starts timer thread.
	 * @param ctrl Parent controller
	 */
	public HostFinder(Controller ctrl)
	{
		this.ctrl = ctrl;
		Thread thrd = new Thread(this);
		thrd.start();
	}
	
	/**
	 * Main thread method. Implements timer. Writes CC_GET_FILES_HOSTS messages to parent controller.
	 */
	public void run()
	{
		while(true)
		{
			try
			{
				Thread.sleep(60000);
				ctrl.writeMsg( new ControllerCommand(ControllerCommandType.CC_GET_FILES_HOSTS) );
				
			} catch (InterruptedException e)
			{
				e.printStackTrace();
			}
		}
	}

}
